<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags/form" %>

<script type="text/javascript">
    var formId = "locale";

    function defaultCode() {
        var countryId = $("#country").val();
        var languageId = $("#language").val();
        $("#code").attr("value", countryId + "_" + languageId);
    }
</script>

<!-- Menu -->
<jsp:include page="menu.jsp"/>

<div class="sub_nav">
    <ul>
        <li>
            <a href="#">
                <img src="<%= request.getContextPath()%>/images/menu/sub_general_on.gif"
                     width="114" height="18" alt="gernal"/>
            </a>
        </li>
    </ul>
</div>

<!--START: conent -->
<div class="content2">
    <div class="insider">
        <div class="corners">
            <div class="corners_top"></div>
            <div class="column1">
                <table width="360" border="0" cellspacing="4" class="formlayout_table"
                       style="margin-left: auto; margin-right: auto;">

                    <spring:form id="locale" modelAttribute="locale" method="post" htmlEscape="true">

                        <input type="hidden" id="submitAction" name="submitAction"/>
                        <input type="hidden" id="from" name="from"/>

                        <tr>
                            <th><label for="Country">Country:</label></th>

                            <td>
                                <c:if test="${IS_CREATE}">
                                    <select name="country.code" id="country" class="select1" onchange="defaultCode();">
                                        <option value="">Choose a Country</option>
                                        <c:forEach items="${countries}" var="country">
                                            <option value="${country.code}"
                                                ${country.code eq locale.country.code ? 'selected' : ''}>
                                                    ${country.code}
                                            </option>
                                        </c:forEach>
                                    </select>
                                </c:if>
                                <c:if test="${IS_EDIT}">
                                    ${locale.country.code}
                                </c:if>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="Language">Language:</label></th>

                            <td>
                                <c:if test="${IS_CREATE}">
                                    <select name="language.code" id="language" class="select1"
                                            onchange="defaultCode();">
                                        <option value="">Choose a Language</option>
                                        <c:forEach items="${languages}" var="language">
                                            <option value="${language.code}"
                                                ${language.code eq locale.language.code ? 'selected' : ''}>
                                                    ${language.code}
                                            </option>
                                        </c:forEach>
                                    </select>
                                </c:if>
                                <c:if test="${IS_EDIT}">
                                    ${locale.language.code}
                                </c:if>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="Code">Locale Code:</label></th>
                            <td>
                                <c:if test="${IS_CREATE}">
                                    <spring:input path="code" id="code" cssClass="input1" maxlength="30"/>
                                </c:if>
                                <c:if test="${IS_EDIT}">
                                    ${locale.code}
                                </c:if>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="Name">Name:</label></th>
                            <td>
                                <spring:input path="name" cssClass="input1" maxlength="255"/>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="DateMask">Date Mask:</label></th>
                            <td>
                                <select name="dateMask.code" class="select1">
                                    <option value="">Choose a Date Mask</option>
                                    <c:forEach items="${dataValidations}" var="dataValidation">
                                        <option value="${dataValidation.code}"
                                            ${dataValidation.code eq locale.dateMask.code ? 'selected' : ''}>
                                                ${dataValidation.code}
                                        </option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="TimeMask">Time Mask:</label></th>
                            <td>
                                <select name="timeMask.code" class="select1">
                                    <option value="">Choose a Time Mask</option>
                                    <c:forEach items="${dataValidations}" var="dataValidation">
                                        <option value="${dataValidation.code}"
                                            ${dataValidation.code eq locale.timeMask.code ? 'selected' : ''}>
                                                ${dataValidation.code}
                                        </option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="DateTimeMask">Datetime Mask:</label></th>
                            <td>
                                <select name="datetimeMask.code" class="select1">
                                    <option value="">Choose a Datetime Mask</option>
                                    <c:forEach items="${dataValidations}" var="dataValidation">
                                        <option value="${dataValidation.code}"
                                            ${dataValidation.code eq locale.datetimeMask.code ? 'selected' : ''}>
                                                ${dataValidation.code}
                                        </option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>

                        <tr>
                            <th><label for="First Name">Description:</label></th>
                            <td>
                                <spring:input path="description" id="Description" cssClass="input1" maxlength="255"/>
                            </td>
                        </tr>

                        <tr class="spacing1">
                            <th><label for="Group">Group:</label></th>
                            <td>
                                <select name="userGroup.name" class="select1">
                                    <c:forEach var="group" items="${groups}">
                                        <option
                                                <c:if test="${group.name eq locale.userGroup.name}">selected</c:if>
                                                value="<c:out value="${group.name}"/>">
                                            <c:out value="${group.name}"/>
                                        </option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                    </spring:form>
                    <tr>
                        <th><label for="Last Modified Date">Last Modified Date:</label></th>
                        <td>
                            <fmt:formatDate value="${locale.modifiedOn}" pattern="dd-MMM-yyyy"/>
                        </td>
                    </tr>

                    <tr>
                        <th><label for="Last Modified By">Last Modified By:</label></th>
                        <td>${locale.modifiedBy.username}</td>
                    </tr>
                </table>
            </div>

            <jsp:include page="../common/commonFunction.jsp"/>

            <div class="corners_bottom"></div>
        </div>

        <div class="message">
            ${message}
            ${empty message ? '' : '<br />'}

            <div style="color:red">
                ${errors['country.errors'][0]}
                ${empty errors['country.errors'] ? '' : '<br />'}

                ${errors['language.errors'][0]}
                ${empty errors['language.errors'] ? '' : '<br />'}

                ${errors['id.errors'][0]}
                ${empty errors['id.errors'] ? '' : '<br />'}

                ${errors['code.errors'][0]}
                ${empty errors['code.errors'] ? '' : '<br />'}

                ${errors['name.errors'][0]}
                ${empty errors['name.errors'] ? '' : '<br />'}

                ${errors['description.errors'][0]}
                ${empty errors['description.errors'] ? '' : '<br />'}

                ${errors['dateMask.errors'][0]}
                ${empty errors['dateMask.errors'] ? '' : '<br />'}

                ${errors['timeMask.errors'][0]}
                ${empty errors['timeMask.errors'] ? '' : '<br />'}

                ${errors['datetimeMask.errors'][0]}
                ${empty errors['datetimeMask.errors'] ? '' : '<br />'}

                ${errors['userGroup.errors'][0]}
                ${empty errors['userGroup.errors'] ? '' : '<br />'}
            </div>
        </div>
    </div>
</div>